//
//  XLCamgirlView.m
//  XiangLove
//
//  Created by 陈宪栋 on 2017/11/30.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "XLCamgirlView.h"
#import "NewCamgirlModel.h"
#import <UIImageView+YYWebImage.h>

@interface XLCamgirlView ()
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) UILabel *ageLabel;
@property (nonatomic, strong) UILabel *addressLabel;
@property (nonatomic, strong) UILabel *chatTimeLabel;
@property (nonatomic, strong) UIImageView *chatImageView;
@property (nonatomic, strong) UIView *ageBGView;
@property (nonatomic, strong) UIView *addressBGView;
@property (nonatomic, strong) UIView *timeBGView;
@end

@implementation XLCamgirlView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView {
    self.clipsToBounds = YES;
    self.layer.cornerRadius = 10;
    
    _imageView = [[UIImageView alloc] init];
    _imageView.userInteractionEnabled = YES;
    _imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self addSubview:_imageView];
    [_imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    _nickNameLabel = [[UILabel alloc] init];
    _nickNameLabel.font = [UIFont systemFontOfSize:30];
    _nickNameLabel.textColor = [UIColor whiteColor];
    [self addSubview:_nickNameLabel];
    [_nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(14);
        make.bottom.equalTo(self.mas_bottom).offset(-70);
    }];
    
    _ageLabel = [[UILabel alloc] init];
    _ageLabel.font = [UIFont systemFontOfSize:12];
    _ageLabel.textColor = [UIColor whiteColor];
    [self addSubview:_ageLabel];
    [_ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_nickNameLabel.mas_left).offset(5);
        make.top.equalTo(_nickNameLabel.mas_bottom).offset(10);
    }];
    
    _addressLabel = [[UILabel alloc] init];
    _addressLabel.font = [UIFont systemFontOfSize:12];
    _addressLabel.textColor = [UIColor whiteColor];
    [self addSubview:_addressLabel];
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_ageLabel.mas_right).offset(20);
        make.top.equalTo(_ageLabel.mas_top);
    }];
    
    _chatTimeLabel = [[UILabel alloc] init];
    _chatTimeLabel.font = [UIFont systemFontOfSize:12];
    _chatTimeLabel.textColor = [UIColor whiteColor];
    [self addSubview:_chatTimeLabel];
    [_chatTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_ageLabel.mas_left);
        make.top.equalTo(_ageLabel.mas_bottom).offset(10);
    }];
    
    _chatImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"xl_video_chat_btn"]];
    _chatImageView.userInteractionEnabled = YES;
    [self addSubview:_chatImageView];
    [_chatImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(80, 69));
        make.right.equalTo(self.mas_right);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    _ageBGView = [[UIView alloc] init];
    _ageBGView.backgroundColor = RGBA(0, 0, 0, 0.3);
    _ageBGView.layer.cornerRadius = 10;
    [self insertSubview:_ageBGView belowSubview:_ageLabel];
    [_ageBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_ageLabel).insets(UIEdgeInsetsMake(-3, -5, -3, -5));
    }];
    
    _addressBGView = [[UIView alloc] init];
    _addressBGView.backgroundColor = RGBA(0, 0, 0, 0.3);
    _addressBGView.layer.cornerRadius = 10;
    [self insertSubview:_addressBGView belowSubview:_addressLabel];
    [_addressBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_addressLabel).insets(UIEdgeInsetsMake(-3, -5, -3, -5));
    }];
    
    _timeBGView = [[UIView alloc] init];
    _timeBGView.backgroundColor = RGBA(0, 0, 0, 0.3);
    _timeBGView.layer.cornerRadius = 10;
    [self insertSubview:_timeBGView belowSubview:_chatTimeLabel];
    [_timeBGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_chatTimeLabel).insets(UIEdgeInsetsMake(-3, -5, -3, -5));
    }];
}

- (void)setModel:(NewCamgirlModel *)model {
    _model = model;
    _nickNameLabel.text = model.NickName;
    //_ageLabel.text = F(@"%@%@", [model.Sex isEqualToString:@"0"] ? @"♂" : @"♀", model.Age);
    _addressLabel.text = model.HostCity;
    _chatTimeLabel.text = F(@"已接听%@分钟", model.WhenLong);
    [_nickNameLabel sizeToFit];
    [_ageLabel sizeToFit];
    [_addressLabel sizeToFit];
    [_chatTimeLabel sizeToFit];
    [_imageView setImageWithURL:[NSURL URLWithString:model.VideoImg] placeholder:[UIImage imageNamed:@""]];
    
    _nickNameLabel.hidden   = YES;
    _ageLabel.hidden        = YES;
    _addressLabel.hidden    = YES;
    _chatTimeLabel.hidden   = YES;
    _ageBGView.hidden       = YES;
    _addressBGView.hidden   = YES;
    _timeBGView.hidden      = YES;
    _chatImageView.hidden   = YES;
}

- (void)showInfo {
    _nickNameLabel.hidden   = NO;
    _ageLabel.hidden        = NO;
    _addressLabel.hidden    = NO;
    _chatTimeLabel.hidden   = NO;
    _ageBGView.hidden       = NO;
    _addressBGView.hidden   = NO;
    _timeBGView.hidden      = NO;
    _chatImageView.hidden   = NO;
}

@end
